import pymssql
# https://blog.csdn.net/Yt7589/article/details/82142548
# 201 济南有人，202 稳恒，203 智泽，204 山东有人


class MssqlHelper:
    connection = None
    cursor = None

    def __init__(self, db_name='UFDATA_201_2018'):
        self.connection = pymssql.connect(server='192.168.0.62:14345',
                                          user='sa', password='sa.123', database=db_name)
        self.cursor = self.connection.cursor()

    def close_connection(self):
        self.connection.close()

    def query_one(self, sql):
        self.cursor.execute(sql)
        return self.cursor.fetchone()

    def query_all(self, sql):
        self.cursor.execute(sql)
        return self.cursor.fetchall()

    def update(self, sql):
        self.cursor.execute(sql)
        self.connection.commit()
